﻿<CodeSnippetTabbed>
    <CodeSnippetTabPage Text="Razor">@(@"<DxDataGrid Data=""@DataSource""
            DataNavigationMode=""DataGridNavigationMode.VirtualScrolling""
            RowRemoving=""@((dataItem) => OnRowRemoving(dataItem))""
            RowUpdating=""@((updatingDataItem, newValues) => OnRowUpdating(updatingDataItem, newValues))""
            RowInserting=""@((newValues) => OnRowInserting(newValues))""
            CssClass=""mw-1100"">

    <DxDataGridCommandColumn Width=""150px""></DxDataGridCommandColumn>

    <DxDataGridColumn Field=""@nameof(Product.Id)"" Caption=""ID"" Width=""50px"">
    </DxDataGridColumn>

    <DxDataGridColumn Field=""@nameof(Product.ProductName)"" Caption=""Product Name"">
    </DxDataGridColumn>

    <DxDataGridColumn Field=""@nameof(Product.Availability)"" Caption=""Availability"" Width=""85px"">
        <DisplayTemplate>
            @{
                var id = Guid.NewGuid().ToString();
                var inStock = (context as Product).Availability;
                <DxCheckBox Id=""@id"" Checked=""@inStock"" Enabled=""false"">
                    @if(inStock) {
                    <label class=""form-check-label text-success"" for=""@id""><span>In stock</span></label>
                    } else {
                    <label class=""form-check-label text-danger"" for=""@id""><span>Sold out</span></label>
                    }
                </DxCheckBox>
            }
        </DisplayTemplate>
        <EditTemplate>
            <DxComboBox Data=""@(new List<string>() { ""In stock"", ""Sold out"" })""
                        Value=""@(((bool)((CellEditContext)context).CellValue) ? ""In stock"" : ""Sold out"" )""
                        ValueChanged=""@((string newCellValue) => ((CellEditContext)context).OnChanged(newCellValue == ""In stock""))"">
            </DxComboBox>
        </EditTemplate>
    </DxDataGridColumn>

    <DxDataGridColumn Field=""@nameof(Product.ProductCategoryId)"" Caption=""Category"">
        <DisplayTemplate>
            @{
                var item = NestedDataSource.Where(x => x.SubcategoryID == (int)((context as Product).ProductCategoryId)).FirstOrDefault();
                string category = item != null ? item.Category.ToString() : ""none"";
                string subcategory = item != null ? item.Subcategory : ""none"";
                <span>@category/@subcategory</span>
            }
        </DisplayTemplate>
        <EditTemplate>
            <DxComboBox Data=""@NestedDataSource""
                        TextFieldName=""CategorySubcategory""
                        Value=""@(NestedDataSource.Where(x => x.SubcategoryID == (int)((CellEditContext)context).CellValue).FirstOrDefault())""
                        ValueChanged=""@((ProductCategory newCellValue) => ((CellEditContext)context).OnChanged(newCellValue.SubcategoryID))"">
            </DxComboBox>
        </EditTemplate>
    </DxDataGridColumn>

</DxDataGrid>")</CodeSnippetTabPage>
</CodeSnippetTabbed>
